package com.concurrent.entity;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.concurrent.CountDownLatch;

/**
 * @program: concurrent_project
 * @description: 张三、李四和王五的用户类
 * @author: Wednesday
 * @create: 2020-06-10 10:12
 **/
public class User implements Runnable{

    private CountDownLatch latch;
    private String name;

    public User(CountDownLatch latch, String name) {
        this.latch = latch;
        this.name = name;
    }


    @Override
    public void run() {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
            Random random = new Random();

            System.out.println(sdf.format(new Date())+ " " + name + "出发去动物园");
            Thread.sleep((long) (random.nextDouble()*3000)+1000);
            System.out.println(sdf.format(new Date()) + " " + name + "到了动物园");
            latch.countDown();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
